% TEST_ID: LANG-EXPAND-0016
% CATEGORY: language/array-ops/expand
% 测试 struct 数组的扩展行为

function test_struct_expand
    % create a scalar struct
    C = struct('x', 1, 'y', 2);

    % expand struct would merge keys of two struct
    C(3) = struct('z', 1);

    names = fieldnames(C);
    assert(names{1} == 'x');
    assert(names{2} == 'y');
    assert(names{3} == 'z');

    % other fields is empty double array
    assert(isempty(C(1).z));
    assert(isempty(C(2).x));
    assert(isempty(C(2).y));
    assert(isempty(C(2).z));
    assert(isempty(C(3).x));
    assert(isempty(C(3).y));
end